﻿using System;
using System.Collections.Generic;
using System.Web.Http;
using Newtonsoft.Json;
using Sovigaz.DataProvider;
using Sovigaz.Permission.Repositories;
using Utilities;

namespace Sovigaz.Permission.Api
{
    public class ProductMovementApiController : ApiController
    {
        public ProductMovementRepository Get(int? pageNumber, string orderBy, string orderDirection, string barCode, string partnerName, string datefrom, string dateto)
        {
            try
            {
                string whereClause = "IsDeleted != true AND Type.Contains(\"R\")";
                if (!String.IsNullOrWhiteSpace(barCode))
                    whereClause = String.Format(whereClause + " AND barCode.Contains(\"{0}\")", barCode);
                if (!String.IsNullOrWhiteSpace(partnerName))
                    whereClause = String.Format(whereClause + " AND partnerName.Contains(\"{0}\")", partnerName);
                return new ProductMovementRepository().Getlist(whereClause, orderBy, orderDirection, pageNumber ?? 1);
            }
            catch (Exception e)
            {
                throw ExceptionHelper.CreateHttpResponseException("Có lỗi xảy ra khi truy xuất dữ liệu.", e);
            }
        }
    }

 
}
